<?php
declare (strict_types = 1);

namespace app\adminapi\controller\organize;

use adminmatrix\admin\BaseController;
use adminmatrix\admin\service\JsonService;
use app\adminapi\logic\organize\AdminOrganizationLogic;
use app\Request;
use think\response\Json;
use hg\apidoc\annotation as Apidoc;
#[
    Apidoc\Title("组织列表"),
    Apidoc\Group("organize")
]
class OrganizationController extends BaseController
{
    #[
        Apidoc\Title("获取组织列表"),
        Apidoc\Tag("组织列表")
    ]
    public function lists() :Json
    {
        return $this->dataLists();
    }

    #[
        Apidoc\Title("新增组织"),
        Apidoc\Method("POST"),
        Apidoc\Author("Xiaobin"),
        Apidoc\Tag("组织列表")
    ]
    public function save(Request $request , AdminOrganizationLogic $organization ) : Json
    {
        try {
            $organization->save($request);
            return JsonService::success("新增组织成功");
        } catch (\Exception $e)
        {
            return JsonService::fail($e->getMessage());
        }
    }

    #[
        Apidoc\Title("更新组织"),
        Apidoc\Method("PUT"),
        Apidoc\Author("Xiaobin"),
        Apidoc\Tag("组织列表")
    ]
    public function update(Request $request , AdminOrganizationLogic $organizationLogic) :Json
    {
        try {
            $organizationLogic->update($request);
            return  JsonService::success('更新组织成功');
        } catch (\Exception $e)
        {
            return  JsonService::fail($e->getMessage());
        }
    }

    #[
        Apidoc\Title("删除组织"),
        Apidoc\Method("DELETE"),
        Apidoc\Author("Xiaobin"),
        Apidoc\Tag("组织列表")
    ]
    public function delete(Request $request ,AdminOrganizationLogic $organizationLogic) : Json
    {
        try {
            $organizationLogic->delete($request);
            return  JsonService::success("组织删除成功");
        } catch (\Exception $e)
        {
            return  JsonService::fail($e->getMessage());
        }
    }
}
